package io.gitee.zhangbinhub.acp.boot.test

import io.gitee.zhangbinhub.acp.boot.exceptions.WebException
import io.gitee.zhangbinhub.acp.boot.vo.ErrorVo
import org.apache.commons.lang3.exception.ExceptionUtils
import org.junit.jupiter.api.Test
import org.noear.snack4.ONode

class TestSimple {

    @Test
    fun printStack() {
        try {
            throw WebException("test error!")
        } catch (e: Exception) {
            println(e)
            println(ExceptionUtils.getStackTrace(e))
        }
    }

    @Test
    fun testJson() {
        val errorVo = ErrorVo()
        println(ONode.serialize(errorVo))
        println(ONode.serialize(errorVo.apply {
            this.error = "test error"
            this.errorDescription = "test error description"
        }))
        val jsonString = """
            {"code":1,"error":"demo error","errorDescription":"hello world"}
        """.trimIndent()
        val vo: ErrorVo = ONode.deserialize(jsonString, ErrorVo::class.java)
        println(vo)
    }
}